package sctu.edu.java.year2016.team01.xuhanmei.day20160531.KnowList;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/31.
 */
public class ListDemo {
    public static void main(String[] args) {
        String a = "你", b = "是", c = "学", d = "霸", e = "你", f = "说", g = "什", h = "么", i = "都",
                j = "对", l = "帅", m = "帅";
        List<String> k = new LinkedList<String>();//创建集合名叫k
        k.add(a);//向集合里添加元素
        k.add(b);
        k.add(c);
        k.add(d);
        k.add(e);
        k.add(f);
        k.add(g);
        k.add(h);
        k.add(i);
        k.add(j);


        Iterator<String> firstIterator = k.iterator();//创建集合的迭代器
        System.out.println("修改前集合里的元素是：");
        while (firstIterator.hasNext()) {//遍历集合中的元素
            System.out.print(firstIterator.next() + "  ");
        }

        k.set(0, l);//将索引位置为0的元素修改为l
        k.add(1, m);//将m添加到索引位置为1的位置
        k.remove(10);//移除索引位置为10的元素
        Iterator<String> it = k.iterator();//创建修改后的集合对象的迭代器
        System.out.println();
        System.out.println("修改后的集合元素是：");
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
    }
}
